package pl.edu.agh.anomalyids.lerad.aspect.implementation;

import pl.edu.agh.anomalyids.lerad.aspect.enums.AspectType;
import pl.edu.agh.anomalyids.lerad.aspect.enums.Match;
import pl.edu.agh.anomalyids.network.Packet;
import pl.edu.agh.anomalyids.network.Packet.Protocol;
import pl.edu.agh.anomalyids.network.header.Header;
import pl.edu.agh.anomalyids.network.header.impl.IPv4Header;

public class DestIpAddressAspect extends IpAddressAspect {

	private static final long serialVersionUID = -4159958548738671755L;

	public DestIpAddressAspect(String ip) {
		super(ip, AspectType.DESTIP);
	}

	@Override
	public Match packetMatchesAspect(Packet packet) {
		Header header = packet.getProtocols().get(Protocol.IPv4);
		if (header != null) {
			IPv4Header ip = (IPv4Header) header;
			if (validate(ip.getDestAddress())) {
				return Match.SAME;
			} else {
				return Match.DIFFER;
			}
		}
		return Match.UNKNOWN;
	}

}
